package com.test.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.test.entity.dto.Interact;
import com.test.entity.dto.Topic;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TopicMapper extends BaseMapper<Topic> {
//    @Select("""
//            select * from account left join db_topic on account.id = db_topic.uid
//            order by `time` desc
//            limit ${start},10
//            """)
//    List<Topic> getTopicList(int start);
//    @Select("""
//            select * from account left join db_topic on account.id = db_topic.uid
//            where type = #{type}
//            order by `time` desc
//            limit ${start},10
//            """)
//    List<Topic> getTopicListByType(int type, int start);
@Insert("<script>\n" +
        "insert ignore into db_interact_${type} values\n" +
        "<foreach collection=\"interacts\" item=\"item\" separator=\",\">\n" +
        "(#{item.tid}, #{item.uid}, #{item.time})\n" +
        "</foreach>\n" +
        "</script>")
void addInteract(List<Interact> interacts, String type);

    @Delete("<script>\n" +
            "delete from db_interact_${type} where \n" +
            "<foreach collection=\"interacts\" item=\"item\" separator=\" or \">\n" +
            "(tid = #{item.tid} and uid = #{item.uid})\n" +
            "</foreach>\n" +
            "</script>")
    int deleteInteract(List<Interact> interacts, String type);
    @Select("select count(*) from db_interact_${type} where tid = #{tid}")
    int getInteractCount(int tid, String type);
    @Select("select count(*) from db_interact_${type} where tid = #{tid} and uid = #{uid}")
    int getInteractStatus(int tid, int uid, String type);
    //从数据库中连表查询uid=uid的贴子列表
    @Select("""
            select * from db_interact_collect  left join db_topic on db_topic.id = db_interact_collect.tid
            where db_interact_collect.uid = #{uid}
            """)
    List<Topic> getCollects(int uid);


}
